package cn.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.crm.Service.IRoleService;
import cn.crm.common.ServerResponse;
import cn.crm.entity.Role;

@Controller
@RequestMapping(value="role")
public class RoleController {

	@Autowired
	private IRoleService roleservice;
	
	@RequestMapping(value="torolepage")
	public String topage(){
		return "role/role_list";
	}
	
	@RequestMapping(value="pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Role role){
		return 	roleservice.pageList(page,limit,role);
				}
	
	@RequestMapping(value="toAddPage")
	public String toaddpage(){
		return "role/role_add";
	}
	
	@RequestMapping(value="selectAllRoles")
	@ResponseBody
	public ServerResponse selectAllRoles(){
		return roleservice.selectAllRoles();
	}
	
	
	@RequestMapping(value="insert")
	@ResponseBody
	public ServerResponse insert(Role role,String permissions){
		return roleservice.insert(role,permissions);
	}
	
	
	@RequestMapping(value="toupdatepage")
	public String toupdatepage(Integer roleId){
		return "role/role_update";
	}
	
	
	@RequestMapping(value="selectRoleandPermissions")
	@ResponseBody
	public ServerResponse selectRoleandPermissions(Integer roleId){
		return roleservice.selectRoleandPermissions(roleId);
	}
	
	
	@RequestMapping(value="update")
	@ResponseBody
	public ServerResponse update(Role role,String permissions){
		return roleservice.update(role,permissions);
	}
}
